﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace SCS.DAL
{
	/// <summary>
	/// 数据访问类:JX_Specialty
	/// </summary>
	public partial class JX_Specialty
	{
		public JX_Specialty()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(SCS.Model.JX_Specialty model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ZYDM != null)
			{
				strSql1.Append("ZYDM,");
				strSql2.Append("'"+model.ZYDM+"',");
			}
			if (model.ZYMC != null)
			{
				strSql1.Append("ZYMC,");
				strSql2.Append("'"+model.ZYMC+"',");
			}
			if (model.ZYYWMC != null)
			{
				strSql1.Append("ZYYWMC,");
				strSql2.Append("'"+model.ZYYWMC+"',");
			}
			if (model.Length != null)
			{
				strSql1.Append("Length,");
				strSql2.Append(""+model.Length+",");
			}
			if (model.ZYLX != null)
			{
				strSql1.Append("ZYLX,");
				strSql2.Append("'"+model.ZYLX+"',");
			}
			if (model.Mark != null)
			{
				strSql1.Append("Mark,");
				strSql2.Append(""+(model.Mark? 1 : 0) +",");
			}
			if (model.admin != null)
			{
				strSql1.Append("admin,");
				strSql2.Append("'"+model.admin+"',");
			}
			if (model.DepartID != null)
			{
				strSql1.Append("DepartID,");
				strSql2.Append("'"+model.DepartID+"',");
			}
			if (model.DepartFZR != null)
			{
				strSql1.Append("DepartFZR,");
				strSql2.Append("'"+model.DepartFZR+"',");
			}
			if (model.SSCC != null)
			{
				strSql1.Append("SSCC,");
				strSql2.Append("'"+model.SSCC+"',");
			}
			if (model.YXSH != null)
			{
				strSql1.Append("YXSH,");
				strSql2.Append("'"+model.YXSH+"',");
			}
			strSql.Append("insert into JX_Specialty(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(SCS.Model.JX_Specialty model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JX_Specialty set ");
			if (model.ZYDM != null)
			{
				strSql.Append("ZYDM='"+model.ZYDM+"',");
			}
			if (model.ZYMC != null)
			{
				strSql.Append("ZYMC='"+model.ZYMC+"',");
			}
			else
			{
				strSql.Append("ZYMC= null ,");
			}
			if (model.ZYYWMC != null)
			{
				strSql.Append("ZYYWMC='"+model.ZYYWMC+"',");
			}
			else
			{
				strSql.Append("ZYYWMC= null ,");
			}
			if (model.Length != null)
			{
				strSql.Append("Length="+model.Length+",");
			}
			else
			{
				strSql.Append("Length= null ,");
			}
			if (model.ZYLX != null)
			{
				strSql.Append("ZYLX='"+model.ZYLX+"',");
			}
			else
			{
				strSql.Append("ZYLX= null ,");
			}
			if (model.Mark != null)
			{
				strSql.Append("Mark="+ (model.Mark? 1 : 0) +",");
			}
			else
			{
				strSql.Append("Mark= null ,");
			}
			if (model.admin != null)
			{
				strSql.Append("admin='"+model.admin+"',");
			}
			else
			{
				strSql.Append("admin= null ,");
			}
			if (model.DepartID != null)
			{
				strSql.Append("DepartID='"+model.DepartID+"',");
			}
			else
			{
				strSql.Append("DepartID= null ,");
			}
			if (model.DepartFZR != null)
			{
				strSql.Append("DepartFZR='"+model.DepartFZR+"',");
			}
			else
			{
				strSql.Append("DepartFZR= null ,");
			}
			if (model.SSCC != null)
			{
				strSql.Append("SSCC='"+model.SSCC+"',");
			}
			else
			{
				strSql.Append("SSCC= null ,");
			}
			if (model.YXSH != null)
			{
				strSql.Append("YXSH='"+model.YXSH+"',");
			}
			else
			{
				strSql.Append("YXSH= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JX_Specialty ");
			strSql.Append(" where " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_Specialty GetModel()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ZYDM,ZYMC,ZYYWMC,Length,ZYLX,Mark,admin,DepartID,DepartFZR,SSCC,YXSH ");
			strSql.Append(" from JX_Specialty ");
			strSql.Append(" where " );
			SCS.Model.JX_Specialty model=new SCS.Model.JX_Specialty();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_Specialty DataRowToModel(DataRow row)
		{
			SCS.Model.JX_Specialty model=new SCS.Model.JX_Specialty();
			if (row != null)
			{
				if(row["ZYDM"]!=null)
				{
					model.ZYDM=row["ZYDM"].ToString();
				}
				if(row["ZYMC"]!=null)
				{
					model.ZYMC=row["ZYMC"].ToString();
				}
				if(row["ZYYWMC"]!=null)
				{
					model.ZYYWMC=row["ZYYWMC"].ToString();
				}
				if(row["Length"]!=null && row["Length"].ToString()!="")
				{
					model.Length=int.Parse(row["Length"].ToString());
				}
				if(row["ZYLX"]!=null)
				{
					model.ZYLX=row["ZYLX"].ToString();
				}
				if(row["Mark"]!=null && row["Mark"].ToString()!="")
				{
					if((row["Mark"].ToString()=="1")||(row["Mark"].ToString().ToLower()=="true"))
					{
						model.Mark=true;
					}
					else
					{
						model.Mark=false;
					}
				}
				if(row["admin"]!=null)
				{
					model.admin=row["admin"].ToString();
				}
				if(row["DepartID"]!=null)
				{
					model.DepartID=row["DepartID"].ToString();
				}
				if(row["DepartFZR"]!=null)
				{
					model.DepartFZR=row["DepartFZR"].ToString();
				}
				if(row["SSCC"]!=null)
				{
					model.SSCC=row["SSCC"].ToString();
				}
				if(row["YXSH"]!=null)
				{
					model.YXSH=row["YXSH"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ZYDM,ZYMC,ZYYWMC,Length,ZYLX,Mark,admin,DepartID,DepartFZR,SSCC,YXSH ");
			strSql.Append(" FROM JX_Specialty ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ZYDM,ZYMC,ZYYWMC,Length,ZYLX,Mark,admin,DepartID,DepartFZR,SSCC,YXSH ");
			strSql.Append(" FROM JX_Specialty ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JX_Specialty ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.User_ID desc");
			}
			strSql.Append(")AS Row, T.*  from JX_Specialty T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

